package com.button.boot.webservice.configure;

import javax.xml.ws.Endpoint;

import org.apache.cxf.Bus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.button.boot.webservice.service.UserService;

/**
 * 
 * @author Button
 * cxf发布webservice配置
 */
@Configuration
public class CxfConfig {
	/**
     * 此方法用于改变项目中服务名的前缀名
     * 没有改设置:wsdl访问地址为http://127.0.0.1:8080/webservice/services/user?wsdl
     * 使用该设置：wsdl访问地址为：http://127.0.0.1:8080/webservice/soap/user?wsdl 
     * @return
     */
    @SuppressWarnings({ "rawtypes", "unchecked" })
	@Bean
    public ServletRegistrationBean dispatcherServlet() {
        return new ServletRegistrationBean(new CXFServlet(), "/soap/*");
    }

    /**
     * 站点服务
     * 
     **/
    @Bean
    public Endpoint endpoint(Bus bus, UserService userService) {
        EndpointImpl endpoint = new EndpointImpl(bus, userService);
        endpoint.publish("/user");
        return endpoint;
    }
}
